package com.gn.test.use;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @Author: 许啸林
 * @Date: 2022/1/21 16:44
 * Data assess Object
 */
public class BaseDao<T>{
    // 新增数据
    public void insert(T t) {

    }
    // 删除数据
    public boolean delete(T t){
        return true;
    }

    // 修改数据
    public Integer update(T t){
        return  null;
    }

    // 批量查询数据
    public List<T> list(Long index){
        return  null;
    }

    // 泛型方法 拆分集合
    public <E> List<List<E>> splitList(List<E> list, int offset){
        int listSize = list.size();
        List<List<E>> convetList = new ArrayList<>();
        if(listSize <= offset){
            return convetList;
        }
       int page = listSize % offset == 0 ? listSize/offset : listSize/offset + 1;
       for(int i = 0; i < page; i++ ) {
           List<E> currList = new ArrayList<>();
           List<E> pageList = list.stream().skip(i * offset).limit(i * offset + 1).collect(Collectors.toList());
           currList = pageList;
           convetList.add(currList);
       }
       return  convetList;
    }
}
